ADMIN_ROLE_MAP = {
    0: "超级管理员",
    1: "客服",
    2: "技术",
    3: "销售",
    4: "财务",
}

function getAdminUsers(){
    var api = "/backstage/permission/admins";
    $.ajax({
        url: api,
        type: "GET",
        success: function(data, status){
            if(data.status == 200) {
                var admins = data.data;
                $("#adminDataTable").DataTable({
                    data: admins,
                    columnDefs: [
                        {
                            "targets": "adminID",
                            "data": "id",
                        },
                        {
                            "targets": "adminUID",
                            "data": "uid",
                        },
                        {
                            "targets": "adminRole",
                            "data": "admin_role",
                            "render": function(data, type, row) {
                                if(type == "display") {
                                    return ADMIN_ROLE_MAP[row.admin_role];
                                }
                                return data;
                            },
                        },
                        {
                            "targets": "adminEmail",
                            "data": "email",
                        },
                        {
                            "targets": "adminJoinTime",
                            "data": "join_time",
                        },
                        {
                            "targets": "adminOperation",
                            "defaultContent": '<button class="btn btn-primary btn-xs">修改</button>',
                        },
                    ],
                });
            }
            else {
                alert("请求异常，请刷新");
            }
        }
    })
}

$(function(){
    getAdminUsers();
})